import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:giwiki/screens/settings.dart';

class SettingsScreen extends StatefulWidget {
  const SettingsScreen({super.key});

  @override
  State<StatefulWidget> createState() => _SettingsScreenState();
}

class _SettingsScreenState extends State<SettingsScreen> {
  var _text = "";

  @override
  void initState() {
    super.initState();
    rootBundle.loadString("lib/assets/settings.html").then((value) {
      setState(() {
        _text = value;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView(
        padding: const EdgeInsets.all(20),
        children: [
          SafeArea(
            bottom: false,
            child: Container(
              height: 20,
            ),
          ),
          Card(
            color: const Color(0xffe7c496),
            clipBehavior: Clip.hardEdge,
            shape: const RoundedRectangleBorder(
              borderRadius: BorderRadius.all(Radius.circular(8.0)),
            ),
            child: GestureDetector(
              behavior: HitTestBehavior.opaque,
              onTap: () async {
                await userChooseColumnCountSetting(context);
                setState(() {});
              },
              child: Container(
                padding: const EdgeInsets.all(20),
                child: Row(
                  children: [
                    const Expanded(
                      child: Text(
                        "列数",
                        style: TextStyle(
                          fontSize: 20,
                          color: Colors.black,
                        ),
                      ),
                    ),
                    Text(
                      "${columnCountSetting == 0 ? "自动" : columnCountSetting}",
                      style: const TextStyle(
                        fontSize: 20,
                        color: Colors.black,
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
          Container(
            height: 20,
          ),
          Container(
            padding: const EdgeInsets.all(20),
            child: const Text(
              "软件开启时会自动拉取最新数据库, 若您对软件有任何建议或意见, 请联系我. 感谢您的支持! 长按下方链接可复制",
            ),
          ),
          Container(
            padding: const EdgeInsets.all(20),
            child: const SelectableText(
              "https://gitcode.com/niuhuan_cn/genshin_wiki/overview",
            ),
          ),
          Container(
            height: 20,
          ),
          Container(
            padding: const EdgeInsets.all(20),
            child: Html(data: _text),
          ),
        ],
      ),
    );
  }
}
